import * as companySetting from '@/api/company-setting';
const state = {
  // 所有角色列表
  rolesList: {},
  // 根据id获取角色详情
  oneRole: [],
  // 获取所有权限点
  permissionList: [],
}

const mutations = {
  SET_ROLES_LIST: (state, newValue) => {
    state.rolesList = newValue;
  },
  SET_ONE_ROLE: (state, newValue) => {
    state.oneRole = newValue;
  },
  SET_PERMISSION_LIST: (state, newValue) => {
    state.permissionList = newValue;
  }
}

const actions = {
  // 所有角色列表
  async updateRolesList(ctx, params) {
    const res = await companySetting.getRoles(params);
    ctx.commit('SET_ROLES_LIST', res);
  },
  // 根据id获取角色详情
  async updateOneRole(ctx, id) {
    const res = await companySetting.getOneRole(id);
    ctx.commit('SET_ONE_ROLE', res);
  },
  // 获取所有权限点
  async updatePermissionList({ commit }) {
    const res = await companySetting.getPermissionList();
    commit('SET_PERMISSION_LIST', res);
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
